package pdd

import "net/http"

type Options struct {
	Gateway      string // 环境请求地址
	AppKey       string // 应用Key
	AppSecret    string // 秘密
	JsonSimplify bool   // 是否开启JSON返回值的简化模式
	httpClient   *http.Client
}

// Option 为可选参数赋值的函数
type Option func(*Options)

// NewOptions 创建可选参数
func NewOptions(opts ...Option) *Options {
	opt := &Options{
		Gateway:      "https://openapi.kwaixiaodian.com",
		JsonSimplify: true,
		httpClient:   &http.Client{},
	}
	for _, o := range opts {
		o(opt)
	}
	return opt
}

// Gateway 设置环境请求地址
func Gateway(router string) Option {
	return func(o *Options) {
		o.Gateway = router
	}
}

// AppKey 设置应用Key
func AppKey(appKey string) Option {
	return func(o *Options) {
		o.AppKey = appKey
	}
}

// AppSecret 设置秘钥
func AppSecret(appSecret string) Option {
	return func(o *Options) {
		o.AppSecret = appSecret
	}
}

// JSONSimplify 设置是否开启JSON返回值的简化模式
func JSONSimplify(jsonSimplify bool) Option {
	return func(o *Options) {
		o.JsonSimplify = jsonSimplify
	}
}

// HttpClient 设置HTTP客户端
func HttpClient(httpClient *http.Client) Option {
	return func(o *Options) {
		o.httpClient = httpClient
	}
}
